#include <iostream>
using namespace std;

int isPrime(int num){
    if(num<2)    return false;
    for(int i=2;i*i<=num;i++){
        if(num%i==0)    return false;
    }
    return true;
}

signed main()
{
    int n,k;
    cin>>k>>n ;
    while(!isPrime(k))    k++;
    int hash[k] = {0};
    int flag = 0;
    for(int i=0;i<n;i++){
        int num,p;
        cin>>num;
        p = num%k;
        if(flag)    cout<<" ";
        if(!hash[p]){
            hash[p] = 1;
            cout<<p;
        }
        else{
            int t = 1,isfind = 0;;
            while(t<k){
                int m = (num+t*t)%k;
                if(!hash[m]){
                    hash[m] = 1;
                    cout<<m;
                    isfind = 1;
                    break;
                }
                t++;
            }
            if(!isfind)    cout<<"-";
        }
        flag = 1;
    }
    return 0;
}